package com.lhb.order.service.impl;

import com.lhb.common.threadlocal.UserContext;
import com.lhb.order.feignClient.RepertoryClient;
import com.lhb.order.mapper.OrderMapper;
import com.lhb.order.model.Order;
import com.lhb.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

/**
 * @author 86131
 * @version 1.0
 * @description
 * @date 2025/8/12 下午5:06
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RepertoryClient repertoryClient;
    @Override
    public void addOrder(Order order) {
        order.setUserId(UserContext.getUser());
        orderMapper.addOrder(order);

    }

    @Override
    public List<Order> getAllOrder() {

        return orderMapper.getAllOrder(UserContext.getUser());
    }

    @Override
    public List<Order> getPaid() {


        return orderMapper.getPaid(UserContext.getUser(),1);
    }

    @Override
    public List<Order> getUnpaid() {


        return orderMapper.getUnpaid(UserContext.getUser(),0);
    }

    @Override
    public void deleteOrder(Long id) {
        orderMapper.deleteOrder(id);
    }

    @Transactional
    @Override
    public void modifyOrder(Long id, Long flightId) throws IOException {
        orderMapper.modifyOrder(id);
        orderMapper.deleteRepertory(flightId);
        repertoryClient.deleteFlight(flightId);
    }


}
